<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2022/4/6
  Time: 22:34
  To change this template use File | Settings | File Templates.
--%>
<%--        引入架包--%>
<%--引入指令--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>显示所有图书列表</title>
</head>
<body>
    <h3>书籍列表</h3>
    <a href="addbook.html">添加图书</a>
    <table border="1" width="90%">
        <tr>
            <th>编号</th>
            <th>书名</th>
            <th>作者</th>
            <th>出版时间</th>
            <th>出版社</th>
            <th>isbn</th>
            <th>价格</th>
            <th>图片</th>
            <th>类别</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${bookList}" var="book">
        <tr>
            <td>${book.id}</td>
            <td>${book.title}</td>
            <td>${book.author}</td>
<%--            时间优化--%>
<%--            <td>${book.publicDate}</td>--%>
            <td><fmt:formatDate value="${book.publicDate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
            
            <td>${book.publisher}</td>
            <td>${book.isbn}</td>
            <td>${book.price}</td>
            <td>${book.picture}</td>
            <td>${book.cid}</td>
            <td>
                <c:url var="updateurl" value="/updatueri">
                    <c:param name="id" value="${book.id}"></c:param>
                </c:url>
                <a href="${updateurl}">更新</a>


                <c:url var="deleteurl" value="/deletebook">
                    <c:param name="id" value="${book.id}"></c:param>
                </c:url>
             <a onclick="return confirm('确定要删除吗?')" href="${deleteurl}">删除</a>
            </td>
        </tr>
        </c:forEach>
        <tr>
            <td colspan="10">
                <!--  pageContext.request.contextPath可以获取到 http://localhost:8080/bookList-->
                <a href="<c:url  value='/bookList?pageIndex=1'></c:url> ">首页</a>

                <!--如果当前在第一页, 不能点击上一页-->

                  <c:if test="${page.pageIndex > 1}">
                    <a href="<c:url  value='/bookList?pageIndex=${page.pageIndex - 1}'></c:url> ">上一页</a>
                </c:if>

                <!--点击下一页, 需要判断, 当前页一定小于总页数-->
                <c:if test="${page.pageIndex < page.totalPages}">
                    <a href="<c:url  value='/bookList?pageIndex=${page.pageIndex + 1}'></c:url>">下一页</a>
                </c:if>

                <!--点击下一页, 判断如果当前页等于总页数, 不允许点击下一页-->
                <c:if test="${page.pageIndex == page.totalPages}">
                    <a>下一页</a>
                </c:if>

                <!--尾页 = 最后一页也就是总页数-->
                <a href="<c:url  value='/bookList?pageIndex=${page.totalPages}'></c:url>">尾页</a>

            </td>
        </tr>

    </table>
</body>
</html>
